package ch.usi.inf.pf2.analyzer;
import junit.framework.TestCase;
import ch.usi.inf.pf2.alu.UnrecognizedIdentifierException;
import ch.usi.inf.pf2.analyzer.Analyzer;

/**
 * @author Thomas Mantegazzi, Yotam Sharon
 * @date 22 april 2010
 */


public class TestAnalyzer extends TestCase {

		private Analyzer a;
		
		protected void setUp() {
			a = new Analyzer();
			a.setText("Sum(A1:A3) - 12*2/2 +1^2");
		}
		
		public void testGetCurrentToken() {
			assertEquals(null,a.getCurrentToken());
		}
		
		public void testFetchNextToken() throws UnrecognizedTokenException, UnrecognizedIdentifierException {
			a.fetchNextToken();
			assertEquals("Sum",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("(",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("A1",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals(":",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("A3",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals(")",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("-",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("12",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("*",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("2",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("/",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("2",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("+",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("1",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("^",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals("2",a.getCurrentToken().getText());
			a.fetchNextToken();
			assertEquals(null,a.getCurrentToken().getText());
		}
		
}
